package com.zj.framework.utils.test;

import com.alibaba.fastjson.JSON;
import com.zj.framework.baseto.type.DatePattern;
import com.zj.framework.utils.ZjDateUtils;
import com.zj.framework.utils.test.bean.MidCountLog;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.*;

/**
 * @author xi.yang(xi.yang@downjoy.com)
 * @create 2018-06-14 下午 4:26
 **/
public class MissionLoginTodayFile {
    @Test
    public void name() throws Exception {
        List<Long> mids = getMids();
        String fileName = "C:\\Users\\Administrator\\Desktop\\part-00000";
        List<String> logs = readFile(fileName);
        int count = 0;
        for (String log : logs) {
            long mid = Long.parseLong(log.replace("[", "").replace("]", "").split(",")[0]);
            if (!mids.contains(mid)) {
                continue;
            }
            count++;
            System.out.println("mids.add("+mid+"L);");
        }
        System.out.println(count);
    }


    private List<Long> getMids() {
        String midFile = "C:\\Users\\Administrator\\Desktop\\mids.txt";
        List<String> list = readFile(midFile);
        List<Long> mids = new ArrayList<>();
        for (String s : list) {
            mids.add(Long.parseLong(s));
        }
        return mids;
    }

    private List<String> readFile(String fileName) {
        List<String> list = new ArrayList<>();
        try {
            FileInputStream fis = new FileInputStream(new File(fileName));
            BufferedReader br = new BufferedReader(new InputStreamReader(fis));
            String line;
            while ((line = br.readLine()) != null) {
                if (StringUtils.isNotBlank(line)) {
                    list.add(line);
                }
            }
            br.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }
}
